<?php
class Gallery_Form_ImageAdd extends Promotor_Form_Scaffold {
	public function init() {
		$this->setMethod('post');
		
		$this->setDecorators(array(
			'FormElements',
            array('TabContainer', array(
                'id' => 'tabContainer',
                'style' => 'width: 100%; height: 500px;',
                'dijitParams' => array(
                    'tabPosition' => 'left'
                ),
            )),
            'Dojo_ValidateOnSubmit',
            'DijitForm',
        ))
        ->addPrefixPath('Promotor_Form_Decorator_','Promotor/Form/Decorator', self::DECORATOR);
        
        $this->addElement('SubmitButton','action', array('ignore' => true,'label'=>'Dodaj'));

        $subForm = $this->_getImageForm();
        $this->addSubForm($subForm, 'imagetab');
        
		$subForm = $this->_getContentForm();
        $this->addSubForm($subForm, 'contenttab');
        
        $subForm = $this->_getSeoForm();
        $this->addSubForm($subForm, 'seotab');
        
        $subForm = $this->_getExForm();
        $this->addSubForm($subForm, 'exttab');
	}

	/**
     * @return Zend_Dojo_Form_SubForm
     */
	protected function _getImageForm() {
    	$subForm = new Zend_Dojo_Form_SubForm();
        $subForm->setAttribs(array(
            'name'   => 'imagetab',
            'legend' => 'Zdięcie',
        ));
        $subForm
        	->addElement(new KontorX_Form_Element_File('image', array(
        		'label' => 'Zdięcie',
        		'required' => true,
        		'destination' => Gallery_Model_Image::UPLOAD_PATH,
        		'filters' => array(
        			'UniqName' => new KontorX_Filter_File_UniqName()
        		),
        		'validators' => array(
        			'upload' => array(
        				'validator' => 'Upload'),
        			'isImage' => array(
        				'validator' => 'IsImage'),
        			'size' => array(
        				'validator' => 'Size',
        				'options' => array(
        					'min' => '3kb',
        					'bytestring' => true)),
        			'count' => array(
        				'validator' => 'Count',
        				'options' => array(
        					'max' => 1))
        		)
        	)));
        	
        $album = new Gallery_Model_Album();
       	$multiOptions = $album->fetchAllGruperByGallery();
        $subForm->addElement('select','album_id', array(
            	'label' => 'Album',
                'description' => 'Wybierz album, do którego będzie należeć zdięcie',
            	'required' => true,
        		'registerInArrayValidator' => false,
            	'multiOptions' => (array) $multiOptions
            ));
        return $subForm;
    }

	/**
     * @return Zend_Dojo_Form_SubForm
     */
    protected function _getContentForm() {
    	$subForm = new Zend_Dojo_Form_SubForm();
        $subForm->setAttribs(array(
            'name'   => 'contenttab',
            'legend' => 'Treść',
        ));
        $subForm
        	->addElement(
                'ValidationTextBox',
                'name',
                array(
                    'label' => 'Nazwa zdięcia'
                )
            );
		$content = new Zend_Form_Element_Textarea('description', array(
			'label'        => 'Opis albumu',
			'inheritWidth' => 'true'
		));
		$content->addDecorator(new KontorX_Form_Decorator_TinyMCE());
		$subForm->addElement($content);

        return $subForm;
    }

    /**
     * @return Zend_Dojo_Form_SubForm
     */
    protected function _getSeoForm() {
    	$subForm = new Zend_Dojo_Form_SubForm();
        $subForm->setAttribs(array(
            'name'   => 'metatab',
            'legend' => 'Pozycjonowanie'
        ));
        $subForm
            ->addElement(
                'Textarea',
                'meta_keywords',
                array(
                    'label'      => 'Słowa kluczowe',
                    'trim'       => true
				)
            )
            ->addElement(
                'Textarea',
                'meta_description',
                array(
                    'label'      => 'Opis strony',
                    'trim'       => true
                )
            );
            
        return $subForm;
    }
    
	/**
     * @return Zend_Dojo_Form_SubForm
     */
    protected function _getExForm() {
    	$subForm = new Zend_Dojo_Form_SubForm();
        $subForm->setAttribs(array(
            'name'   => 'exttab',
            'legend' => 'Zaawansowane'
        ));
        $subForm
            ->addElement(
            	'CheckBox',
            	'publicated',
            	array(
            		'label' => 'Publikować',
            		'value' => 1,
            		'checked' => true
            	)
            );
            
        return $subForm;
    }
}